using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Threading;
using System.Web.Services.Description;

#pragma warning disable 1591

namespace Agron.Services.Proxies
{
    /// <summary>
    /// Defines the proxy based on the <see cref="SoapHttpClientProtocol"/> for the AddressInfoService web service.
    /// </summary>
    [WebServiceBindingAttribute(Name = "AddressInfoServiceSoap", Namespace = "http://services.udlap.mx/Agron/AddressInfoService.asmx")]
    public class AddressInfoServiceProxy : SoapHttpClientProtocol
    {
        private SendOrPostCallback _getIPAddressOperationCompleted;

        /// <summary>
        /// Initializes a new instance of the <see cref="AddressInfoServiceProxy"/> class.
        /// </summary>
        public AddressInfoServiceProxy(string url)
        {
            this.Url = url;
        }

        /// <summary>
        /// Occurs when <see cref="AddressInfoServiceProxy.GetIPAddress"/> asynchronous processing is complete.
        /// </summary>
        public event GetIPAddressCompletedEventHandler GetIPAddressCompleted;

        /// <summary>
        /// Gets the IP address of the caller.
        /// </summary>
        /// <returns>
        /// A <see cref="string"/> containing the IP Address of the caller.
        /// </returns>
        [SoapDocumentMethodAttribute("http://services.udlap.mx/Agron/AddressInfoService.asmx/GetIPAddress", 
            RequestNamespace = "http://services.udlap.mx/Agron/AddressInfoService.asmx", 
            ResponseNamespace = "http://services.udlap.mx/Agron/AddressInfoService.asmx", 
            Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
        public string GetIPAddress()
        {
            object[] results = this.Invoke("GetIPAddress", new object[0]);
            return ((string) (results[0]));
        }

        /// <summary>
        /// Invokes asynchronously the <see cref="AddressInfoServiceProxy.GetIPAddress"/> method.
        /// </summary>
        public void GetIPAddressAsync()
        {
            this.GetIPAddressAsync(null);
        }

        /// <summary>
        /// Invokes asynchronously the <see cref="AddressInfoServiceProxy.GetIPAddress"/> method.
        /// </summary>
        /// <param name="userState">Additional data.</param>
        public void GetIPAddressAsync(object userState)
        {
            if ((this._getIPAddressOperationCompleted == null))
            {
                this._getIPAddressOperationCompleted = new SendOrPostCallback(this.OnGetIPAddressOperationCompleted);
            }
            this.InvokeAsync("GetIPAddress", new object[0], this._getIPAddressOperationCompleted, userState);
        }

        private void OnGetIPAddressOperationCompleted(object arg)
        {
            if ((this.GetIPAddressCompleted != null))
            {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs) (arg));
                this.GetIPAddressCompleted(this, new GetIPAddressCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        /// <summary>
        /// Cancels an asynchronous call to an XML Web service method, unless the call has already completed.
        /// </summary>
        /// <param name="userState">The object provided in the last parameter to the asynchronous call of the Begin method.</param>
        public new void CancelAsync(object userState)
        {
            base.CancelAsync(userState);
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public delegate void GetIPAddressCompletedEventHandler(object sender, GetIPAddressCompletedEventArgs e);

    /// <summary>
    /// 
    /// </summary>
    public partial class GetIPAddressCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
    {

        private object[] results;

        internal GetIPAddressCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState)
            :
                base(exception, cancelled, userState)
        {
            this.results = results;
        }

        /// <summary>
        /// Gets the result.
        /// </summary>
        /// <value>The result.</value>
        public string Result
        {
            get
            {
                this.RaiseExceptionIfNecessary();
                return ((string) (this.results[0]));
            }
        }
    }
}
#pragma warning restore 1591